#include <sys/types.h>          /* See NOTES */
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>

#include "proto.h"

int main(void)
{
	struct sockaddr_in raddr;
	struct msg_st snd_data;
	int udp_socket = socket(AF_INET, SOCK_DGRAM, 0);
	if (-1 == udp_socket) {
		perror("socket()");
		exit(1);
	}

	// 发数据
	snd_data.id = 1;
	strncpy(snd_data.name, "张三", NAMESIZE);
	
	raddr.sin_family = AF_INET;
	inet_aton(RCVADDR, &raddr.sin_addr);
	raddr.sin_port = htons(PORT);

	sendto(udp_socket, &snd_data, sizeof(snd_data.id) + strlen(snd_data.name) + 1, \
			0, (struct sockaddr *)&raddr, sizeof(raddr));

	close(udp_socket);

	return 0;
ERROR:
	close(udp_socket);
	exit(1);
}




